package com.szpx.controller.HZJController;

 

 
import com.github.pagehelper.PageInfo;
import com.szpx.entity.HZJ.DrivingSchoolRegistration;
import com.szpx.service.DrivingSchoolRegistrationService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/drivingSchoolRegistration")
public class DrivingSchoolRegistrationController {

    @Autowired
    private DrivingSchoolRegistrationService service;

//保存注册报名信息
    @PostMapping
    public void saveRegistration(@RequestBody DrivingSchoolRegistration registration) {
        service.saveRegistration(registration);
    }
    //删除注册报名信息
    @DeleteMapping("/{idCard}")
    public void deleteRegistration(@PathVariable String idCard) {
        service.deleteRegistration(idCard);
    }
    //更新注册报名信息
    @PutMapping
    public void updateRegistration(@RequestBody DrivingSchoolRegistration registration) {
        service.updateRegistration(registration);
    }
    //获取注册报名信息
    @GetMapping("/{idCard}")
    public DrivingSchoolRegistration getRegistration(@PathVariable String idCard) {
        return service.getRegistrationByIdCard(idCard);
    }
    //获取所有注册报名信息
    @GetMapping("/all")
    public List<DrivingSchoolRegistration> getAllRegistrations() {
        return service.getAllRegistrations();
    }
    //获取注册报名信息分页
    @GetMapping
    public PageInfo<DrivingSchoolRegistration> getRegistrationsWithPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String classType,
            @RequestParam(required = false) String licenseType) {
                Map<String, Object> params = new HashMap<>();
        if (name != null) params.put("name", name);
        if (classType != null) params.put("classType", classType);
        if (licenseType != null) params.put("licenseType", licenseType); 
        return service.getRegistrationsWithPage(pageNum, pageSize,params);
    }

    @GetMapping("/search")
    public List<DrivingSchoolRegistration> getRegistrationsByConditions(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String classType,
            @RequestParam(required = false) String licenseType) {
        Map<String, Object> params = new HashMap<>();
        if (name != null) params.put("name", name);
        if (classType != null) params.put("classType", classType);
        if (licenseType != null) params.put("licenseType", licenseType);
        return service.getRegistrationsByConditions(params);
    }
}
